﻿using System;
using ITViet.Web.App_Code;
using ITViet.Services;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace ITViet.Web.Pages
{
	public partial class ProductList : BasePage
	{
		#region Events
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack && !IsCallback)
			{
				LoadProduct();
			}
		}

		protected void rptProduct_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
		{
			if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
			{
				DataRowView rowView = e.Item.DataItem as DataRowView;
				if (rowView != null)
				{
					Label lbRefPrice = e.Item.FindControl("lbRefPrice") as Label;
					if (lbRefPrice != null)
					{
						decimal refPrice = rowView["RefPrice"] == DBNull.Value ? 0 : (decimal)rowView["RefPrice"];
						lbRefPrice.Text = refPrice.ToString("#,###.##");
					}
				}
			}
		}
		#endregion

		#region Methods
		private void LoadProduct()
		{
			rptProduct.DataSource = new ProductLocaleService().GetByCatLang(TypeId, CurrentLanguage.Id);
			rptProduct.DataBind();
		}
		#endregion
	}
}
